#!/bin/bash
cd $HOME
#检查权限
source /xrk/shell_modules/update.sh
source /xrk/.init
if [ "$(whoami)" != "root" ]; then
    sudo -i
fi

response=$(curl -s "https://v1.hitokoto.cn")
sentence=$(echo "$response" | jq -r '.hitokoto')

ver1=$(curl -s "https://raw.gitcode.com/Xrkseek/sunflower-yunzai-scripts/raw/master/package.json" | jq -r '.version')
ver2=$(jq -r '.version' /xrk/package.json)

if [ "$ver1" != "$ver2" ]; then
    zhuangtai="${color_red}[请更新]${bg}"
else
    zhuangtai="[已最新]"
fi
current_time=$(date "+%Y-%m-%d %H:%M:%S")

echo -e "${caidan1}${sentence}${bg}"

function clear_menu
{
for ((i=0;i<forin;i++));do
    printf "\e[1A\e[K"
done
}

function show_menu 
{
echo -e "${caidan2}现在的时间是 : $current_time${bg}"
echo -e "${caidan1}任意键退出脚本，当前脚本主管的云崽为$yz${bg}"
echo -e "${caidan2}更新请输入r${bg}"
echo -e "${caidan3}                  __ _                        
 ___ _   _ _ __  / _| | _____      _____ _ __ 
/ __| | | | '_ \| |_| |/ _ \ \ /\ / / _ \ '__|
\__ \ |_| | | | |  _| | (_) \ V  V /  __/ |   
|___/\__,_|_| |_|_| |_|\___/ \_/\_/ \___|_|   ${bg}"
echo -e "${caidan1}        ╭─────────────────────────╮${bg}"
echo -e "${caidan1}        │        向日葵脚本       │${bg}"
echo -e "${caidan1}        ├─────────────────────────┤${bg}"
echo -e "${caidan2}        │     集中营1013495491    │  ${bg}"
echo -e "${caidan1}        ├─────────────────────────┤${bg}"
echo -e "${caidan2}        │      1 安/重装云崽      │${bg}"
echo -e "${caidan1}        ├─────────────────────────┤${bg}   ${caidan1}┌───────────────┐${bg}"
echo -e "${caidan2}        │       2 插件相关        │${bg}   ${caidan1}│${bg}    ${caidan3}脚本状态${bg}   ${caidan1}│${bg}"
echo -e "${caidan1}        ├─────────────────────────┤${bg}   ${caidan1}│${bg}${caidan2}最新版本: ${bg}$ver1${caidan1}│${bg}"
echo -e "${caidan2}        │       3 报错修复        │${bg}  ${caidan1} │${bg}${caidan2}当前版本: ${bg}$ver2${caidan1}│${bg}"
echo -e "${caidan1}        ├─────────────────────────┤${bg}  ${caidan1} │${bg}    ${zhuangtai}   ${caidan1}│${bg}"
echo -e "${caidan2}        │       4 一键换签        │${bg}   ${caidan1}└───────────────┘${bg}"
echo -e "${caidan1}        ├─────────────────────────┤${bg}"
echo -e "${caidan2}        │       5 脚本相关        │${bg}"
echo -e "${caidan1}        ├─────────────────────────┤${bg}"
echo -e "${caidan2}        │      6 安装Napcat       │${bg}"
echo -e "${caidan1}        ├─────────────────────────┤${bg}"
echo -e "${caidan2}        │     7 安装拉格朗日      │${bg}"
echo -e "${caidan1}        ╰─────────────────────────╯${bg}"
echo
}

while true; do
    show_menu
    read -p "请从选项中选一个: " CHOICE
    forin=27 clear_menu
    case "$CHOICE" in
        1 )
        bash <(curl -sL https://raw.gitcode.com/Xrkseek/sunflower-yunzai-scripts/raw/master/linuxinstall.sh)
        ;;
        2 )
        bash /xrk/body/menu/plug-in
        ;;
        3 )
        bash /xrk/body/menu/errorbg
        ;;
        4 )
        node $yz/plugins/XRK/components/xrkksign.js
        break
        ;;
        5 )
        bash /xrk/body/menu/advanced
        break
        ;;
        6 )
        bash /xrk/Yunzai-install/NapCat.sh
        break
        ;;
        7 )
        bash /xrk/Yunzai-install/Lagrange.sh
        break
        ;;
        r )
    echo -e "开始更新至最新脚本"
    cd /xrk
    git pull --no-rebase
    if [ -n "$xyz" ]; then
       葵崽升级
    fi
    双崽linux脚本升级
    echo "更新完成，正在退出"
    exit 1
        ;;
        * )
             echo -e "${red}退啦${bg}"
             exit 1
        ;;
    esac
done